<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
     
	  
	  <el-form-item label="商户名称" prop="companyName">
	    <el-input
	      v-model="queryParams.companyName"
	      placeholder="请输入商户名称"
	      clearable
	      @keyup.enter="handleQuery"
	    />
	  </el-form-item>
     
      <el-form-item label="业务id" prop="relationOrder">
        <el-input
          v-model="queryParams.relationOrder"
          placeholder="请输入关联业务id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" style="width: 308px">
        <el-date-picker
          v-model="daterangeCreateTime"
          value-format="YYYY-MM-DD"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

   <el-row :gutter="10" class="mb8">
   
    
     <el-col :span="1.5">
       <el-button
         type="warning"
         plain
         icon="Download"
         @click="handleExport"
         v-hasPermi="['system:detail:export']"
       >导出</el-button>
     </el-col>
     <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
   </el-row>
    <el-table v-loading="loading" :data="detailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商户名称"  width="250" align="center" prop="companyName"  :show-overflow-tooltip="true"/>
      <el-table-column label="类型" align="center" prop="type">
        <template #default="scope">
          <dict-tag :options="transaction_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="交易金额" align="center" prop="amount" />
      <el-table-column label="余额" align="center" prop="currentAmount" />
      <el-table-column label="描述" align="center" prop="remark" />
      <el-table-column label="关联业务id" align="center" prop="relationOrder" />
	  <el-table-column label="关联借款人" align="center" prop="relationName" />
	  <el-table-column label="交易时间" align="center" prop="createTime" />
     
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script setup name="Detail">
import { listDetail, getDetail, delDetail, addDetail, updateDetail } from "@/api/system/detail";

const { proxy } = getCurrentInstance();
const { transaction_type } = proxy.useDict('transaction_type');

const detailList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const daterangeCreateTime = ref([]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
	companyName: null,
    type: null,
    amount: null,
    currentAmount: null,
    relationOrder: null,
    createTime: null,
  },
  rules: {
    userId: [
      { required: true, message: "用户Id不能为空", trigger: "blur" }
    ],
    createTime: [
      { required: true, message: "创建时间不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询用户资金明细列表 */
function getList() {
  loading.value = true;
  queryParams.value.params = {};
  if (null != daterangeCreateTime && '' != daterangeCreateTime) {
    queryParams.value.params["beginCreateTime"] = daterangeCreateTime.value[0];
    queryParams.value.params["endCreateTime"] = daterangeCreateTime.value[1];
  }
  listDetail(queryParams.value).then(response => {
    detailList.value = response.rows;
    total.value = Number(response.total);
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    userId: null,
    type: null,
    amount: null,
    currentAmount: null,
    remark: null,
    relationOrder: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null
  };
  proxy.resetForm("detailRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  daterangeCreateTime.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}
/** 导出按钮操作 */
function handleExport() {
  proxy.download('system/detail/export', {
    ...queryParams.value
  }, `用户资金明细_${new Date().getTime()}.xlsx`)
}
getList();
</script>
<style scoped>
.app-container {
    background: #ffffff !important;
}
</style>